home *** CD-ROM | disk | FTP | other *** search
- /*
- from engber@gumball.ils.nwu.edu (Mike Engber):
-
- Thanks for all the replys to my centering DLOG/ALRT question. I used the
- best ideas to synthesize my solution which I think elegant enough to be
- worth sharing. Attached are the relevant portions of my .h & .c files.
-
- A couple of notes:
-
- Several people`s solutions burned in the rsrc ids of the standard
- file dialogs. You may want to note that there are named constants for
- these values: putDlgID & getDlgID.
-
- All the solutions I was sent used screenBits.bounds. Is this what you
- want in a multi-monitor situation? If not, what should you do?
-
- Feel free to use/modify/comment-on this code, especially if you notice
- any bugs or questionable practices.
-
- -ME
- */
-
- /* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
-
-
- /* DialogUtils.c */
-
- #include <QuickDraw.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <StandardFile.h>
- #ifndef topLeft
- #define topLeft(r) (((Point *)&(r))[0])
- #endif
- #ifndef botRight
- #define botRight(r) (((Point *)&(r))[1])
- #endif
- #include "DialogUtils.h"
-
- #include "DialogUtils.proto.h"
- static void DU_CenterRect(Rect *rect_p);
- static Point DU_Where(short rsrcId);
- static short DU_Center(ResType type, short rsrcId);
-
- static void DU_CenterRect(Rect* rect_p){
- /*
- * Aligns *rect_p wrt screenBits.bounds - LR centered & in upper 1/3
- */
-
- /* exactly centered */
- OffsetRect(rect_p,
- (qd.screenBits.bounds.right + qd.screenBits.bounds.left)/2 -
- (rect_p->right + rect_p->left)/2
- ,
- (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom)/2 -
- (rect_p->top + rect_p->bottom)/2
- );
-
- /* up a bit */
- OffsetRect(rect_p,0,
- GetMBarHeight() - 2*(rect_p->top - qd.screenBits.bounds.top)/3);
- }
-
- static Point DU_Where(short rsrcId){
- /*
- * Returns centering point for the topLeft corner of a dialog.
- */
- Handle h = GetResource('DLOG',rsrcId);
- Rect r = {0,0,0,0};
- if(h){
- r = *((Rect*)(*h));
- DU_CenterRect(&r);
- ReleaseResource(h);
- }
- return topLeft(r);
- }
-
- Point DU_StdPutWhere(void){
- return DU_Where(putDlgID);
- }
-
- Point DU_StdGetWhere(void){
- return DU_Where(getDlgID);
- }
-
- static short DU_Center(ResType type, short rsrcId){
- /*
- * Reads in an 'ALRT' or 'DLOG' rsrc template & centers it's display Rect.
- */
- Handle h = GetResource(type,rsrcId);
- if(h) DU_CenterRect((Rect*)(*h));
- return rsrcId;
- }
-
- short DU_CenterALRT(short rsrcId){
- return DU_Center('ALRT',rsrcId);
- }
-
- short DU_CenterDLOG(short rsrcId){
- return DU_Center('DLOG',rsrcId);
- }
-